<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    let s = new Set()
    let s1 = new Set(['a','b','c','d','e','b'])

    console.log(s1)//a b c d e

    s1.size //5

    s1.add('p')//a b c d e p

    s1.delete('p')//a b c d e

    s1.has('b')//true
    s1.has('y')//false

    s1.clear() // set(0) 清空

    for (let v of s1){
        console.log(v)//{a,b,c,d,e} ''
    }

    let arr = [1,2,3,4,5,6,3,7,8,9]
    //先转为集合在使用扩展运算符变成数组  去重
    let result = [...new Set(arr)]
    console.log(result)

    let arr1 = [22,11,2,4,6,0]
    let result1 = new Set(arr1)

    //交集
    console.log(result.filter(item => result1.has(item)))

    //并集
    console.log(new Set([...result1,...result]))

    //差集
    console.log(result.filter(item => !(result1.has(item))))
</script>
</body>
</html>